package org.webequa.core.maple.operator.algebra;

import org.apache.log4j.Logger;
import org.webequa.core.common.operator.algebra.Times;
import org.webequa.core.common.quantity.QuantityObject;
import org.webequa.core.maple.operator.MapleNaryOperator;
import org.webequa.core.maple.quantity.MapleQuantityObject;
import org.webequa.core.maple.quantity.MapleQuantityObjectFactory;

import com.maplesoft.externalcall.MapleException;
import com.maplesoft.openmaple.Algebraic;

public class MapleTimes extends MapleNaryOperator implements Times
{
	@Override
	public QuantityObject calculate(QuantityObject operand1, QuantityObject operand2)
	{
		try
		{
			MapleQuantityObject tOp1 = MapleQuantityObjectFactory.getMapleQuantityObject(operand1);
			MapleQuantityObject tOp2 = MapleQuantityObjectFactory.getMapleQuantityObject(operand2);
			String mapleJob = tOp1.getVarName()+"*"+tOp2.getVarName()+":";				
			Algebraic tRes = mapleEngine.evaluate(mapleJob);
			log.info(mapleJob);			
			return MapleQuantityObjectFactory.getMapleQuantityObject(getResultSignature(),tRes);
		} catch (MapleException e)
		{
			log.error(e);
			return null;
		}
	}
	private static final Logger log = Logger.getLogger(MapleTimes.class);	
}
